package com.example.demo.controller;

import com.example.demo.model.Message;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

@RestController
@RequestMapping("/drools")
public class DroolsTest {
    @Autowired
    private KieSession kieSession;

    @RequestMapping("/hellowrold")
    public void helloWrold(){
        System.out.println("hello,drools");
        try {
            Message message1;
            message1 = new Message(Message.MessageType.CHAT, "杨过");
            kieSession.insert(message1);
            kieSession.fireAllRules();
            Message message5 = new Message(null, "loop");
            kieSession.setGlobal("count", new AtomicInteger(0));
            kieSession.insert(message5);
            int i2 = kieSession.fireAllRules();
            System.out.println(i2);
        }finally {
//            kieSession.dispose();
        }


    }
}
